package Day2025_03_26;

import java.util.Scanner;

public class Demo05 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int INF = -0x3f3f3f3f;
        int[] prices = new int[n];
        for (int i = 0; i < n; i++) prices[i] = in.nextInt();
        int[][] dp1 = new int[n + 1][2];
        int[][] dp2 = new int[n + 1][2];
        for (int i = 0; i <= n; i++) dp1[i][0] = INF;
        for (int i = 0; i < 2; i++) dp1[0][i] =  INF;
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 2; j++) {
                dp1[i][j] = Math.max(dp1[i - 1][j], dp2[i - 1][j] - prices[i - 1]);
                dp2[i][j] = dp2[i - 1][j];
                if (j - 1 >= 0) dp2[i][j] = Math.max(dp1[i - 1][j - 1] + prices[i - 1], dp2[i][j]);
            }
        }
        int ret = 0;
        for (int i = 0; i < 2; i++) ret = Math.max(dp2[n][i], ret);
        System.out.println(ret);
    }
}
